// hyb_yl/wodeyuyue/wodeyuyue.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: ["已完成", "已取消/未完成"],

    current: null,
    userInfo: {}
  },
  tab: function (e) {
    var that = this
    var index = e.currentTarget.dataset.index
    
    //console.log(index)
    var openid = wx.getStorageSync('openid')
    //console.log(openid)
    if (index == 0) {
      app.util.request({
        url: 'entry/wxapp/Selectord1',
        data: {
          openid: openid
        },
        method: "POST",
        success: function (res) {
          console.log(res.data.data)
          that.setData({
            selectord: res.data.data,
          })
        }
      })

    } else {
      var openid = wx.getStorageSync('openid')
      app.util.request({
        url: 'entry/wxapp/Selectord2',
        data: {

          openid: openid
        },

        success: function (res) {
          console.log(res)
          that.setData({
            selectord1: res.data.data,
          })
        }
      })
    }

    this.setData({
      current: e.currentTarget.dataset.index
    })
  },
  tab1: function (e) {
    var that = this
    var index = e.currentTarget.dataset.index
//    console.log(index)
    var openid = wx.getStorageSync('openid')
    if (!index) {
//      console.log('s')
      app.util.request({
        url: 'entry/wxapp/Selectord',
        data: {
          openid: openid
        },
        success: function (res) {
          console.log(res.data.data)
          that.setData({
            selectord: res.data.data,
          })
        }
      })
    }

    this.setData({
      current: null
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    wx.login({
      success: function () {
        wx.getUserInfo({
          success: function (res) {
            var simpleUser = res.userInfo;
            that.setData({
              userInfo: simpleUser
            })
          }
        });
      }
    });
  },
  delOrder:function(e){
    var that = this
    var index = e.currentTarget.dataset.index
    var selectord = that.data.selectord
    selectord.splice(index,1)
    var zy_id = e.currentTarget.dataset.id
    app.util.request({
      url: 'entry/wxapp/Delorder',
      data: {
        zy_id: zy_id
      },
      success: function (res) {
        wx.showToast({
          title: '删除成功',
        })

      }
    })
    that.setData({
      selectord: selectord
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  ddxqClick: function (e) {
    var id = e.currentTarget.dataset.id
    var time = e.currentTarget.dataset.time
    app.util.request({
      'url': 'entry/wxapp/Dmoney',
      data: {
        id: id,
      },
      success: function (res) {
        // console.log(res)
        wx.navigateTo({
          url: '/hyb_yl/mysubpages/pages/ddxq/ddxq?id=' + id + '&yytime=' + time,
        })

      },
    })

  },
  getlist: function () {
    var that = this;
    var openid = wx.getStorageSync('openid')
    app.util.request({
      url: 'entry/wxapp/Selectord',
      data: {
        openid: openid
      },
      success: function (res) {
        //console.log(res.data.data)
        that.setData({
          selectord: res.data.data,
        })
      }
    })
  }
})